//
//  MZPluginType.swift
//  MZTool
//
//  Created by gby on 2023/2/7.
//

import Foundation


public protocol MZPluginType {
    
    func prepare(_ request: URLRequest, target: MZApiRequest) -> URLRequest
    
    func willSend(_ request: MZRequestType, target: MZApiRequest)
    
    func didReceive(_ result: Result<MZApiResponse, MZError>, target: MZApiRequest)
    
    func process(_ result: Result<MZApiResponse, MZError>, target: MZApiRequest) -> Result<MZApiResponse, MZError>
    
}

public extension MZPluginType{
    func prepare(_ request: URLRequest, target: MZApiRequest) -> URLRequest { request }
    func willSend(_ request: MZRequestType, target: MZApiRequest) { }
    func didReceive(_ result: Result<MZApiResponse, MZError>, target: MZApiRequest) { }
    func process(_ result: Result<MZApiResponse, MZError>, target: MZApiRequest) -> Result<MZApiResponse, MZError> { result }
}


public protocol MZRequestType {
    
    var request: URLRequest? { get }
    
    var sessionHeaders: [String: String] { get }
    
//    func authenticate(username: String, password: String, persistence: URLCredential.Persistence) -> Self
//    func authenticate(with credential: URLCredential) -> Self
//    func cURLDescription(calling handler: @escaping (String) -> Void) -> Self
}
